/* 
 * File:   comm.h
 * Author: gustavo
 *
 * Created on August 6, 2011, 4:27 AM
 */

#ifndef COMM_H
#define	COMM_H

#include <stdio.h>
#include <stdlib.h>


#define XOR( a, b ) ( !(a) ^ !(b) )

#define imp_alloc(type) (type *) calloc( 1, sizeof(type) )
#define imp_allocn(n, type) (type *) calloc( (n), sizeof(type) )

#define imp_free(p) { if(p) {free(p); p = NULL;} }

#define impAlloc( p, type ) \
{\
	p = (type *) malloc( sizeof(type) );\
	if( p == NULL ) {\
		printf("Macro impAlloc(p, type): Out of memory!\n");\
		exit(EXIT_FAILURE);\
	}\
}

#define impFree( p ) \
{\
	if(p) { free(p); p = NULL; }\
}





#ifdef	__cplusplus
extern "C" {
#endif




#ifdef	__cplusplus
}
#endif

#endif	/* COMM_H */

